﻿using System;
using System.Threading.Tasks;
using Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using MVVMCommon.Repositories;
using OAuthLib;
using RestAPICore;
using SinaWeiboApp.ViewModels.Login;

namespace SinaWeiboApp_ViewModels.Test
{
    [TestClass]
    public class Login_Model_Test
    {
        
        public static Login_Model _initedTestTarget;
        public static Login_Model _notInitedTestTarget;
        public static IRepository<string, AuthToken> _mockedTokenRepository;
        public static JDCBOAuthTokenFactory _OAuthFactory = new JDCBOAuthTokenFactory() ;
        
        
        static Login_Model_Test()
        {
            var RequestTokenUrl = "http://api.t.sina.com.cn/oauth/request_token"; //<--these should get from resource
            var AuthorizeUrl = "http://api.t.sina.com.cn/oauth/authorize"; //<--these should get from resource
            var AccessTokenUrl = "http://api.t.sina.com.cn/oauth/access_token"; //<--these should get from resource
            var appKey="967389259";
            var appSecret= "001379b11292669a5399131cfc5b806d";
            IUserNamePasswordAuthTokenFactory oAuthTokenFactory = new JDCBOAuthTokenFactory   
            {
                AppKey = appKey,
                AppSecret = appSecret,
                RequestTokenUrl = RequestTokenUrl,
                AuthorizeUrl = AuthorizeUrl,
                AccessTokenUrl = AccessTokenUrl,
  
            };


            var mockrp = new Mock<IRepository<string, AuthToken>>();

            mockrp
                .Setup(r => r.GetByKeyAsync("-"))
                .Returns(
                     () =>
                    {
                        return  Task.Factory.StartNew(
                            ()=>(AuthToken) null
                            );
                    }

                );

            mockrp
                .Setup(r => r.SetOrUpdateByKeyAsync("-",null))
               
                .Returns(
                     () =>
                     {
                         return Task.Factory.StartNew(
                             () => true
                             );
                     }

                );
            _mockedTokenRepository = mockrp.Object;
               


            _notInitedTestTarget = new Login_Model();
            _initedTestTarget = new Login_Model();
            
            _initedTestTarget.OAuthTokenRepository = _mockedTokenRepository;
            _initedTestTarget.AuthTokenFactory = oAuthTokenFactory;
            


        }

        [TestClass]
        public class UIProperties
        {
            [TestMethod]
            public void LoginCommandCanExecuteTest()
            {
                
            }
            [TestMethod]
            public void LoginCommandExecuteTest()
            {

            }

            [TestMethod]
            public void CancelCommandCanExecuteTest()
            {

            }
            [TestMethod]
            public void CancelCommandExecuteTest()
            {

            }

        }


    }
}
